﻿namespace System
{
	[Serializable]
	sealed class ArgumentTypeMismatchException : ArgumentException
	{
		public ArgumentTypeMismatchException(string paramName, Type actual, Type expectedType)
			: base(GetMessage(actual, expectedType), paramName)
		{

		}
		public ArgumentTypeMismatchException(string paramName, Type actual, params Type[] expectedTypes)
			: base(GetMessage(actual, expectedTypes), paramName)
		{

		}
		protected ArgumentTypeMismatchException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
			: base(info, context)
		{
		}


		private static string GetMessage(Type actual, Type expected)
		{
			return Loc.GetErrorString("Exception_ArgumentTypeMismatch", actual.Name, expected.Name);
		}
		private static string GetMessage(Type actual, Type[] expected)
		{
			var names = Array.ConvertAll(expected, t => t.Name);
			return Loc.GetErrorString("Exception_ArgumentTypeMismatch", actual, string.Join(", ", names));
		}

	}
}
